package cn.simonfish.carrier.kit;

/**
 * Created by simon on 2017/9/19.
 */
public class NumberKit {

    public static String fill(Integer num,int len){
        long temp = Math.round(Math.pow(10.0,len));
        temp = temp + num;
        String numStr = temp + "";
        return numStr.substring(numStr.length()-len);
    }

    public static void main(String[] args) {
        System.out.println(fill(102,2));
    }

    /**
     *
     * @param obj
     * @param defaultVal
     * @return
     */
    public static Double toDouble(Object obj,Double defaultVal){
        if(obj == null){
            return defaultVal;
        }
        if(obj instanceof Number){
            return ((Number)obj).doubleValue();
        }
        String str = obj.toString();
        if(str.length()<1){
            return defaultVal;
        }else{
            return Double.parseDouble(str);
        }
    }

    public static Integer toInt(Object obj){
        return toInt(obj,0);
    }
    public static Integer toInt(Object obj,Integer defaultVal){
        if(obj == null){
            return defaultVal;
        }
        if(obj instanceof Number){
            return ((Number)obj).intValue();
        }
        String str = obj.toString();
        if(str.length()<1){
            return defaultVal;
        }else{
            return Integer.parseInt(str);
        }
    }
    /**
     *
     * @param obj
     * @return
     */
    public static Double toDouble(Object obj){
        return toDouble(obj,0.0);
    }
}
